#!/usr/bin/perl
use warnings;
use strict;
use Storable;
use Readonly;
Readonly my $width => 1000;

my $topic_dir = shift;
chdir $topic_dir or die "$!";
#for my $sub_dir (qw(BestFirst Accelerated FirstOrder)) {
for my $sub_dir (qw(Accelerated)) {
    my $inFile = "$sub_dir/statistics";
    my $outFile = "$sub_dir/gnuplot.ratio";
    my @statis = @{ Storable::retrieve($inFile) };
    open OUT, "> $outFile" or die "$!";
    my $count = 0;
    my @window = ();
    my $pos_cnt = 0;
    for (@statis) {
        $count++;
        push @window, $_;
        $pos_cnt++ if $_ eq '+';
        if (@window > $width) {
            my $first = shift @window;
            $pos_cnt-- if $first eq '+';
        }
        my $harvest_ratio = sprintf("%.4f", $pos_cnt / @window);
        print OUT $count, "\t", $harvest_ratio, "\n";
    }
    close OUT;
}
print "Done!\n";
